<?php

namespace ChatX\Storage;

class StorageFactory
{
    /**
     * 创建存储服务实例
     *
     * @param string $type 存储类型(minio, oss, cos)
     * @param array $config 配置参数
     * @return Driver
     * @throws \InvalidArgumentException
     */
    public static function create(string $type, array $config = []): Driver
    {
        $className = __NAMESPACE__ . '\\Driver\\' . ucfirst(strtolower($type)) . 'Adapter';

        if (!class_exists($className)) {
            throw new \InvalidArgumentException("不支持的存储类型: {$type}");
        }

        $storage = new $className();
        $storage->connect($config);

        return $storage;
    }
}